home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / giochi / chinacha.lha / ChinaChallenge3 / C++ / cc3.h < prev    next >
C/C++ Source or Header  |  1994-05-09  |  8KB  |  335 lines

  1.  
  2. //
  3. // Header File for China Challenge III - the C++ Version
  4. //
  5. // author    : Gunther Nikl
  6. // created    : 9-may-94
  7. // last change    : 9-may-94
  8. //
  9.  
  10.  
  11. #ifndef _CC3_H
  12. #define _CC3_H
  13.  
  14. //
  15. // all includes
  16. //
  17.  
  18. #include <sys/cdefs.h>
  19.  
  20. __BEGIN_DECLS
  21.  
  22. #include <exec/memory.h>
  23. #include <dos/dosextens.h>
  24. #include <devices/audio.h>
  25. #include <hardware/cia.h>
  26. #include <graphics/gfx.h>
  27. #include <graphics/rastport.h>
  28. #include <intuition/screens.h>
  29. #include <intuition/intuition.h>
  30. #include <proto/intuition.h>
  31. #include <proto/graphics.h>
  32. #include <proto/alib.h>
  33. #include <proto/exec.h>
  34. #include <proto/dos.h>
  35.  
  36. LONG sprintf(STRPTR buffer, STRPTR fmt, ...);
  37.  
  38. //
  39. // oh - a c structure !
  40. //
  41.  
  42. struct About
  43.   UBYTE pens[2],x,y,text[24];
  44. };
  45.  
  46. //
  47. // some defines
  48. //
  49.  
  50. #define DEPTH    3L
  51. #define WIDTH  320L
  52. #define HEIGHT 200L
  53.  
  54. #define MAXCOUNT 120L
  55.  
  56. #define SAMPLESIZE 104072L
  57.  
  58. #define ciaa (*((struct CIA*)0xbfe001L))
  59.  
  60. //
  61. // common globals
  62. //
  63.  
  64. static UBYTE ArpName[]       = "arp.library";
  65. static UBYTE AudioName[]     = "audio.device";
  66. static UBYTE TopazName[]     = "topaz.font";
  67.  
  68. static UBYTE SampleName[]    = "Sample";
  69. static UBYTE PieceFmt[]      = "%3ld";
  70. static UBYTE BlankStr[]      = "   ";
  71.  
  72. static UBYTE AboutStr[]      = "About";
  73. static UBYTE QuitStr[]       = "Quit";
  74. static UBYTE NewGameStr[]    = "New game";
  75. static UBYTE UndoMoveStr[]   = "Undo last move";
  76. static UBYTE UndoAllStr[]    = "Undo all moves";
  77. static UBYTE LoadDragonStr[] = "Load Dragon";
  78. static UBYTE SaveDragonStr[] = "Save Dragon";
  79. static UBYTE PlayMusicStr[]  = "Play Music";
  80. static UBYTE OptionsStr[]    = "Options";
  81. static UBYTE ProjectStr[]    = "Project";
  82.  
  83. static struct About About1[] =
  84. { { {4,0},9,  9,"  China Challenge III  " },
  85.   { {4,0},9, 16,"  -------------------  " },
  86.   { {4,0},9, 29,"    written 1991 by    " },
  87.   { {2,0},9, 44,"     Dirk Hoffmann     " },
  88.   { {4,0},6, 60,"   rewritten 1993 by   " },
  89.   { {2,0},9, 75,"     Gunther Nikl      " },
  90.   { {3,0},9, 89,"This game is Freeware !" },
  91.   { {3,0},9, 99,"       Enjoy ...       " },
  92.   { {2,0},9,112," (dedicated to Astrid) " } };
  93.  
  94. static UBYTE Version[]       = "$VER: China Challenge III 1.0a (9.5.94)";
  95. #define Title (Version+6)
  96.  
  97. static struct TextAttr TopazFont =
  98. { (STRPTR)TopazName,8,FS_NORMAL,FPF_ROMFONT };
  99.  
  100. static struct NewScreen NewScreen =
  101. { 0,0, WIDTH,HEIGHT, DEPTH, 4,2, 0 /* LORES */,
  102.   SCREENQUIET | SCREENBEHIND | CUSTOMSCREEN, &TopazFont, Title, NULL, NULL };
  103.  
  104. static UWORD ColorTab[] =
  105. { 0x000,0xfeb,0xfe9,0xcb7,0xa43,0xc52,0x4a0,0x86b };
  106.  
  107. static struct NewWindow NewWindow =
  108. { 0,1, WIDTH,HEIGHT-2, 2,4,
  109.   MENUPICK | MOUSEBUTTONS, ACTIVATE | BORDERLESS | BACKDROP,
  110.   NULL,NULL,NULL,NULL,NULL,
  111.   WIDTH,HEIGHT-2, WIDTH,HEIGHT-2, CUSTOMSCREEN };
  112.  
  113. static struct NewWindow AboutWindow =
  114. { 57,55, 200,120, 2,2,
  115.   VANILLAKEY | MOUSEBUTTONS, NOCAREREFRESH | RMBTRAP | ACTIVATE | BORDERLESS,
  116.   NULL,NULL,NULL,NULL,NULL,
  117.   200,120,200,120, CUSTOMSCREEN };
  118.  
  119. static struct IntuiText MenuText[] =
  120. { { 2,4, JAM2,  3,1, NULL, AboutStr,      NULL },
  121.   { 2,4, JAM2,  3,1, NULL, QuitStr,       NULL },
  122.   { 2,4, JAM2,  3,1, NULL, NewGameStr,    NULL },
  123.   { 2,4, JAM2,  3,1, NULL, UndoMoveStr,   NULL },
  124.   { 2,4, JAM2,  3,1, NULL, UndoAllStr,    NULL },
  125.   { 2,4, JAM2,  3,1, NULL, LoadDragonStr, NULL },
  126.   { 2,4, JAM2,  3,1, NULL, SaveDragonStr, NULL },
  127.   { 2,4, JAM2, 13,1, NULL, PlayMusicStr,  NULL } };
  128.  
  129. #define IFLAGS1 (HIGHCOMP | ITEMENABLED | COMMSEQ | ITEMTEXT)
  130. #define IFLAGS2 (CHECKED | IFLAGS1 | MENUTOGGLE | CHECKIT)
  131.  
  132. static struct MenuItem MenuItems[] =
  133. { { &MenuItems[1], 2, 2, 80,11, IFLAGS1, NULL, &MenuText[0], NULL, 'a', NULL, 0 },
  134.   { NULL,          2,14, 80,11, IFLAGS1, NULL, &MenuText[1], NULL, 'q', NULL, 0 },
  135.  
  136.   { &MenuItems[3], 2, 2,150,11, IFLAGS1, NULL, &MenuText[2], NULL, 'n', NULL, 0 },
  137.   { &MenuItems[4], 2,14,150,11, IFLAGS1, NULL, &MenuText[3], NULL, 'b', NULL, 0 },
  138.   { &MenuItems[5], 2,26,150,11, IFLAGS1, NULL, &MenuText[4], NULL, 'g', NULL, 0 },
  139.   { &MenuItems[6], 2,38,150,11, IFLAGS1, NULL, &MenuText[5], NULL, 'l', NULL, 0 },
  140.   { &MenuItems[7], 2,50,150,11, IFLAGS1, NULL, &MenuText[6], NULL, 's', NULL, 0 },
  141.   { NULL         , 2,62,150,11, IFLAGS2, NULL, &MenuText[7], NULL, 'm', NULL, 0 } };
  142.  
  143. static struct Menu MenuStrip[] =
  144. { { &MenuStrip[1],  2,2, 60,10, MENUENABLED, (BYTE *)ProjectStr, &MenuItems[0], 0,0,0,0 },
  145.   { NULL,          70,2, 60,10, MENUENABLED, (BYTE *)OptionsStr, &MenuItems[2], 0,0,0,0 } };
  146.  
  147. static WORD Coords[] =
  148. { 0,0, 28,0, 28,33, 0,33, 0,0 };
  149.  
  150. static struct Border Border1[] =
  151. { {   2,84, 1,2, JAM2, 5, &Coords[0], &Border1[1] },
  152.   { 290,84, 1,2, JAM2, 5, &Coords[0], NULL        } };
  153.  
  154. static struct IntuiText MoveIText =
  155. { 2,5, JAM2, 283,53, NULL, BlankStr, NULL };
  156.  
  157. static UBYTE PosTable[] =
  158. { 0xFF,0x8F,0x1F,0xFE,0xE7,0x7F,0xF8,0xF1,0xFF,
  159.   0xFC,0x03,0x0F,0xF8,0x81,0x1F,0xF0,0xC0,0x3F,
  160.   0x60,0x00,0x0F,0xF0,0x00,0x0F,0xF0,0x00,0x06,
  161.   0x00,0x00,0x00,0xF0,0x00,0x0F,0x00,0x00,0x00 };
  162.  
  163. static ULONG APenTab[] = { 0,5,0,2 };
  164.  
  165. static UBYTE ChannelMap[4] = { 3,5,10,12 };
  166.  
  167. static ULONG BackGroundTab[] = { 0,0,160,0,0,99,160,99 };
  168.  
  169. extern struct Image Images[];
  170.  
  171. /* arp filerequest structure */
  172.  
  173. struct FileReq
  174. {
  175.   APTR  fr_Hail;
  176.   APTR  fr_File;
  177.   APTR  fr_Dir;
  178.   APTR  fr_Window;
  179.   UBYTE fr_Flags;
  180.   UBYTE fr_res1;
  181.   APTR  fr_Func;
  182.   LONG  fr_res2;
  183. };
  184.  
  185. /* cc3 request definition */
  186.  
  187. struct ChinaReq
  188. {
  189.   struct FileReq FReq;
  190.   UWORD  Pad;
  191.   UBYTE  DirBuf[256];
  192.   UBYTE  FileBuf[128];
  193. };
  194.  
  195. /* arp inlines */
  196.  
  197. static __inline ULONG
  198. FileRequest (struct Library *ArpBase,struct FileReq *req)
  199. {
  200.   register ULONG _res __asm("d0");
  201.   register struct Library *a6 __asm("a6") = ArpBase;
  202.   register struct FileReq *a0 __asm("a0") = req;
  203.   __asm __volatile ("jsr a6@(-294)"
  204.   : "=r" (_res)
  205.   : "r" (a6), "r" (a0)
  206.   : "a0","a1","d0","d1", "memory");
  207.   return _res;
  208. }
  209.  
  210. static __inline VOID
  211. TackOn (struct Library *ArpBase,UBYTE *dir, UBYTE *file)
  212. {
  213.   register struct Library *a6 __asm("a6") = ArpBase;
  214.   register UBYTE *a0 __asm("a0") = dir;
  215.   register UBYTE *a1 __asm("a1") = file;
  216.   __asm __volatile ("jsr a6@(-624)"
  217.   : /* no output */
  218.   : "r" (a6), "r" (a0), "r" (a1)
  219.   : "a0","a1","d0","d1", "memory");
  220. }
  221.   
  222. static __inline BPTR 
  223. ArpOpen (struct Library *ArpBase,UBYTE *name,LONG accessMode)
  224. {
  225.   register BPTR  _res  __asm("d0");
  226.   register struct Library *a6 __asm("a6") = ArpBase;
  227.   register UBYTE *d1 __asm("d1") = name;
  228.   register LONG d2 __asm("d2") = accessMode;
  229.   __asm __volatile ("jsr a6@(-0x1e)"
  230.   : "=r" (_res)
  231.   : "r" (a6), "r" (d1), "r" (d2)
  232.   : "a0","a1","d0","d1","d2", "memory");
  233.   return _res;
  234. }
  235.  
  236. __END_DECLS
  237.  
  238. //
  239. // class definitions
  240. //
  241.  
  242. // one undo entry :)
  243.  
  244. class Undo
  245. {
  246.  public:
  247.    UWORD pos1,pos2;
  248. };
  249.  
  250. // game class
  251.  
  252. struct Dragon
  253. {
  254.  public:
  255.    class Undo UndoTable[60];
  256.    BYTE PieceTable[288];
  257. };
  258.  
  259. // main class
  260.  
  261. class China
  262. {
  263.    // public class functions
  264.  
  265.  public:
  266.    China();
  267.    ~China() { FreeMusic(); CloseGfx(); };
  268.  
  269.    LONG Init();
  270.    VOID Game();
  271.  
  272.  private:
  273.  
  274.    // private class functions
  275.  
  276.    VOID InitMusic();
  277.    LONG MakeGfx();
  278.  
  279.    VOID CloseGfx();
  280.    VOID FreeMusic();
  281.  
  282.    VOID DoIDCMP(ULONG imClass, ULONG imCode);
  283.  
  284.    VOID ProjectAbout();
  285.    VOID ProjectQuit();
  286.  
  287.    VOID OptNewGame();
  288.    VOID OptUndoMove();
  289.    VOID OptUndoAll();
  290.    VOID OptLoadDragon();
  291.    VOID OptSaveDragon();
  292.    VOID OptMusic();
  293.  
  294.    LONG CheckPos();
  295.  
  296.    VOID MakeDragon();
  297.    LONG Random(ULONG);
  298.    VOID ShowDragon();
  299.    VOID PrintPieces();
  300.  
  301.    BPTR ReqFile(LONG);
  302.  
  303.    // variables
  304.  
  305.    struct Screen *ScrPtr;
  306.    struct Window *WinPtr;
  307.    APTR SampleBuf;
  308.    LONG PiecePos1,PiecePos2;
  309.    ULONG RandVal,PieceCount;
  310.    ULONG TwoSelected,OnePiece;
  311.    BYTE Music,EndAll,AudioOpen;
  312.    struct MsgPort AudioPort;
  313.    struct IOAudio AudioIO;
  314.    struct RastPort RastPort;
  315.    struct BitMap BitMap;
  316.    UBYTE EntryTable[MAXCOUNT];
  317.    class Dragon NewDragon;
  318. };
  319.  
  320. VOID ChangeFunc();
  321.  
  322. /*
  323. ** NewList() as macro
  324. */
  325.  
  326. #define NEWLIST(l) ((l)->lh_Head = (struct Node *)&(l)->lh_Tail, \
  327.                     (l)->lh_TailPred = (struct Node *)&(l)->lh_Head)
  328.  
  329. #endif /* _CC3_H */
  330.  
  331. //
  332. // end of Header File for China Challenge III - the C++ Version
  333. //
  334.